package com.yupao.common;

import com.yupao.model.enums.ErrorCode;

public class ResultUtils {

    /**
     * 成功
     * @param data
     * @return
     * @param <T>
     */
    public static <T> BaseResponse<T> success(T data){
        return new BaseResponse<T>(0, data, "ok");
    }

    /**
     * 失败
     * @param errorCode
     * @return
     * @param <T>
     */
    public static <T> BaseResponse<T> error(ErrorCode errorCode){
        return new BaseResponse<>(errorCode);
    }

    public static <T> BaseResponse<T> error(int code, String msg){
        return new BaseResponse<>(code, null, msg);
    }

    public static <T> BaseResponse<T> error(ErrorCode errorCode, String msg){
        return new BaseResponse<>(errorCode.getCode(), null, msg);
    }
}
